#include "ddc/ddc_spf.h"
#include "ddc/ddc.h"
#include "cmn/util.h"

struct cr_floyd_match *strTestMatch;
struct cr_floyd_matrix* floyd_matric_before;

int  cr_ddc_DatabaseInit(int *lidb_handler)
{
	struct cr_ddc_master	 *strddcMaster;

	if((*lidb_handler)!=0)
	{
		cr_ddc_DatabaseFree(*lidb_handler);
	}
	strddcMaster		= (struct cr_ddc_master *)(malloc(sizeof(struct cr_ddc_master)));
	*lidb_handler = (int)strddcMaster;

	if(!strddcMaster)
	{
		return -1;
	}
	//flag
	strddcMaster->flag				= 0;
	//cache
	strddcMaster->cacheAdjacent		= NULL;
	strddcMaster->cache_linkShadow	= NULL;
	strddcMaster->cachePath			= NULL;
	//path and linkShadow
	strddcMaster->firstPath			= NULL;
	strddcMaster->lastPath			= NULL;
	strddcMaster->first_linkShadow	= NULL;
	strddcMaster->last_linkShadow	= NULL;
	return 1;
}

int	cr_ddc_DatabaseFree(int lidb_handler)
{
	struct cr_ddc_master *strMaster	=(struct cr_ddc_master *)lidb_handler;
	strMaster->flag		 = 0;
	struct cr_ddc_linkShadow	*strLinkShadow	= strMaster->first_linkShadow;

	while(strLinkShadow)
	{
		if(strLinkShadow->lastAdjacent)
		{
			strLinkShadow->lastAdjacent->next	= strMaster->cacheAdjacent;
			strMaster->cacheAdjacent			= strLinkShadow->firstAdjacent;
			strLinkShadow->firstAdjacent		= NULL;
			strLinkShadow->lastAdjacent			= NULL;
		}
		strLinkShadow=strLinkShadow->next;
	}

		if(strMaster->lastPath)
		{
			strMaster->lastPath->next		= strMaster->cachePath;
			strMaster->cachePath			= strMaster->firstPath;
		}
		strMaster->firstPath				= NULL;
		strMaster->lastPath					= NULL;

		if(strMaster ->last_linkShadow)
		{
			strMaster->last_linkShadow->next	= strMaster->cache_linkShadow;
			strMaster->cache_linkShadow			= strMaster->first_linkShadow;
		}
		strMaster->first_linkShadow				= NULL;
		strMaster->last_linkShadow				= NULL;


	return 0;
}

struct cr_floyd_match *	cr_ddc_initFloydMatch(int lsdb_handler )
{
	int 	lsdbNodeCount;
	struct cr_floyd_match  *strMatchHead;
	int 					i	=1;
	struct cr_lsdb_router *cr_lsdb_head;

	lsdbNodeCount		=  cr_lsdb_get_routers_count(lsdb_handler);
	if(lsdbNodeCount==0)
	{
		strMatchHead = NULL;
	}

	cr_lsdb_get_routers(&cr_lsdb_head, lsdb_handler);

	strMatchHead	= (struct cr_floyd_match *)malloc(lsdbNodeCount*sizeof(struct cr_floyd_match));

	if(!strMatchHead)
	{
		strMatchHead = NULL;
	}

	for (i = 0; i <lsdbNodeCount; i++)
	{
		struct cr_lsdb_router *tmp = cr_lsdb_head;
		strMatchHead[i].routerID	= cr_lsdb_head->id;
		strMatchHead[i].num			= i;
		cr_lsdb_head	= cr_lsdb_head->next;
		free(tmp);
	}
	strTestMatch	= strMatchHead;
	return strMatchHead;
}

int  cr_ddc_freeFloydMatch(struct cr_floyd_match *p_head)
	{
		struct cr_floyd_match *p;
		p=p_head;
		if(p)
		{
			free(p);
		}
		return 0;
	}

int  cr_ddc_freeFloydMatrix(struct cr_floyd_matrix *p_matrixHead)
{
	struct cr_floyd_matrix *p;
	p	= p_matrixHead;
	if(p)
	{
		free(p);
	}
	return 0;
}

int cr_ddc_searchNumByRouterID(struct cr_floyd_match *head,int length, int pRouterID)
{
	int i;
		for (i = 0; i < length; i++)
		{
			if (head[i].routerID == pRouterID)
			{
				return (head[i].num);
			}
		}
		return -1;
}

int cr_ddc_searchRouterIDByNum(struct cr_floyd_match *head,int length, int num)
{
	int i;
		for (i = 0; i < length; i++)
		{
			if (head[i].num == num)
			{
				return (head[i].routerID);
			}
		}
		return -1;
}

int 	ddc_compute_Floyd(int *lidb_handler,int lsdb_handler)
{
	struct cr_floyd_matrix	*fm		=NULL;
	struct  cr_floyd_match	*fmatch =NULL;
	struct cr_route_table	*route_table =NULL;
	int length;//compute lsdb's length
	int use,i;
   length = cr_lsdb_get_routers_count(lsdb_handler);
	//cr_ddc_DatabaseInit(lidb_handler);
	fmatch	=	init_floyd_match(lsdb_handler);
	fm=	init_floyd_matrix(fmatch,lsdb_handler);
	print_match(fmatch,length);



	int router_id = 0;
	while(router_id < length)
	{
		route_table	= malloc_z(struct cr_route_table);
		route_table->table	= route_table_init();

		cr_spf_calculation (fm,fmatch,router_id,route_table,length);

		cr_node_print(route_table,router_id);

		free(route_table->table);
		route_table->table = NULL;

		free(route_table);
		route_table = NULL;

		router_id += 1;
	}

	nexthop_choose(fm,fmatch,length,lsdb_handler);// choose the minimum if_id
	printf("program came here\n");
	//fm= floyd(*lidb_handler,lsdb_handler);
	print_floyd(fm,fmatch,length,lsdb_handler);

   //cr_ddc_sPathRecord(fmatch,fm,*lidb_handler,lsdb_handler);
	//just for print every link's importance value

//	cr_lsdb_get_links_state(&cr_lsdbLinkhead, lsdb_handler);
//	while(cr_lsdbLinkhead)
//	{
//		if(cr_lsdbLinkhead->key.n_rt_id == 0)
//		{
//			cr_lsdbLinkhead		= cr_lsdbLinkhead->next;
//			continue;
//		}
//		use = cr_lsd_is_connected(cr_lsdbLinkhead, lsdb_handler);
//		if(use==1)
//		{
//			//importance_value =cr_ddc_get_link_important_value(cr_lsdbLinkhead,lsdb_handler);
//			//printf("\n%d-%d, importance value is %d\n",cr_lsdbLinkhead->key.rt_id,cr_lsdbLinkhead->key.n_rt_id,importance_value);
//			printf("\n link:%d->%d shadow is%p\n",cr_lsdbLinkhead->key.rt_id,cr_lsdbLinkhead->key.n_rt_id,cr_lsdbLinkhead->shadow);
//		}
//		cr_lsdbLinkhead = cr_lsdbLinkhead->next;
//	}


	free(fmatch);
	fmatch = NULL;
	for(i=0;i<length;i++)
	{
		if(fm[i].link)
		{
			free(fm[i].link);
			fm[i].link = NULL;
		}
	}
	free(fm);
	fm=NULL;
	return 0;
}
struct cr_floyd_matrix *floyd(int lidb_handler ,int lsdb_handler)
{

	//struct cr_li_master *strMaster	=(struct cr_li_master *)lidb_handler;
	struct cr_floyd_match  *strMatchHead;
	struct cr_floyd_matrix	*strMatrixHead;
	int length	= cr_lsdb_get_routers_count(lsdb_handler);
	int i,j,k;
	int totalLength;
	struct cr_floyd_matrix *strMatrix_ij,*strMatrix_ik,*strMatrix_kj;
	strMatchHead	=cr_ddc_initFloydMatch(lsdb_handler);
	if(strMatchHead==NULL)
	{
		return NULL;
	}
	strMatrixHead	=	init_floyd_matrix(strMatchHead,lsdb_handler);
	totalLength	= length*length*sizeof(struct cr_floyd_matrix);
	//floyd_matric_before	= malloc(totalLength);
	//memcpy(floyd_matric_before,strMatrixHead,totalLength);
	//printFloyd(strMatrixHead, lidb_handler,lsdb_handler);
	if(!strMatrixHead)
	{
		return NULL;
	}
	for(k=0;k<length;k++)
	{
		for(i=0;i<length;i++)
		{
			for(j=0;j<length;j++)
			{
				strMatrix_ik	= (struct cr_floyd_matrix *)((char *)strMatrixHead + (i*length+k)*sizeof(struct cr_floyd_matrix));
				strMatrix_kj	= (struct cr_floyd_matrix *)((char *)strMatrixHead + (k*length+j)*sizeof(struct cr_floyd_matrix));


				if(strMatrix_ik->metric==MAX_METRIC	|| strMatrix_kj->metric == MAX_METRIC)
				{
					continue;
				}

				strMatrix_ij	= (struct cr_floyd_matrix *)((char *)strMatrixHead + (i*length+j)*sizeof(struct cr_floyd_matrix));

				if( (strMatrix_ik->metric + strMatrix_kj ->metric)  < strMatrix_ij->metric)
				{
					strMatrix_ij->metric	=(strMatrix_ik->metric	+ strMatrix_kj->metric);
					strMatrix_ij->nextHop	= strMatrix_ik->nextHop;
				}

			}
		}
	}//锟斤拷锟窖拷锟斤拷锟斤拷锟?

	return strMatrixHead;
}

int print(struct cr_lsdb_router *strNode, struct cr_lsdb_link_state *link, void* args)
{
	int* p = args;
	*p += link->metric;
	//printf("%d - %d:", link.rt_id, link.if_id);
	//("%d\n", link.metric);
	return NO_ERR;
}
int  cr_ddc_getNodeALValue(int lsdb_handler,int rid)
{
	int count = 0;
	//rid=	cr_li_searchIDByRouterID(strTestMatch,6,rid);
	cr_lsdb_access_links_state_accept_by_router(rid,print, &count, lsdb_handler);
	//printf("\n%d\n",count);
	return count;
}

int 	 cr_ddc_sPathRecord(struct cr_floyd_match *strTestMatch,struct cr_floyd_matrix *p_strMatrixhead,int lidb_handler,int lsdb_handler)
{
	struct cr_floyd_matrix *matrixElement	= NULL;
	struct cr_floyd_matrix *strMatrixHead	=p_strMatrixhead;
	struct cr_ddc_master *strMaster	=(struct cr_ddc_master *)lidb_handler;
	int i,j;
	int thisNode,nextHop;
	int nodeLength	=  cr_lsdb_get_routers_count(lsdb_handler);
	struct cr_ddc_path *path	= NULL;


	strMaster->flag	= 0;
	printf("\n ===record every link's all shortest path begin====\n");
	for(i=0;i<nodeLength;i++)
	{
		for(j=0;j<nodeLength;j++)
		{
			if(i<j)
			{
				continue;
			}
			matrixElement	= (struct cr_floyd_matrix *)((char *)strMatrixHead + (i*nodeLength+j)*sizeof(struct cr_floyd_matrix));

			if(matrixElement->metric == MAX_METRIC||matrixElement->metric==0)
			{
				continue;
			}
			else
			{
				matrixElement->path				=cr_ddc_pathAdd(lidb_handler) ;
				matrixElement->path->raID		= cr_ddc_searchRouterIDByNum(strTestMatch,nodeLength,i);;//matrixElement->link->rta_id;
				matrixElement->path->rbID		= cr_ddc_searchRouterIDByNum(strTestMatch,nodeLength,j);//matrixElement->link->rtb_id;
				matrixElement->path->distance_metric += matrixElement->metric;
				matrixElement->path->spathValue = cr_ddc_getNodeALValue(lsdb_handler,matrixElement->path->raID) *cr_ddc_getNodeALValue(lsdb_handler,matrixElement->path->rbID);
				//memcpy(&matrixElement->path->nexthop,&matrixElement->nexthop,sizeof(matrixElement->nexthop));
				//matrixElement->path->next_hop_router_id	= matrixElement->nextHop;
				strMaster->flag++;

			}
			path = matrixElement->path;
			thisNode = i;
			nextHop = matrixElement->nextHop;

			while(nextHop!=j && nextHop>0)
			{
				matrixElement	= (struct cr_floyd_matrix *)( (char*)strMatrixHead+(thisNode*nodeLength+nextHop)*sizeof(struct cr_floyd_matrix));
				cr_ddc_adjacentLinkShadowAndPath(lidb_handler,lsdb_handler,path,matrixElement->link,i,j);
				matrixElement	=(struct cr_floyd_matrix *)( (char*)strMatrixHead+(nextHop*nodeLength+j)*sizeof(struct cr_floyd_matrix));
				thisNode		= nextHop;
				nextHop			= matrixElement->nextHop;
			}
			if(matrixElement->link)
			{
				cr_ddc_adjacentLinkShadowAndPath(lidb_handler,lsdb_handler,path,matrixElement->link,i,j);
			}


		}
	}
	printf("\n ===record every link's all shortest path end====\n");
	return 0;
}

struct cr_ddc_path	* cr_ddc_pathAdd(int lidb_handler)
{
	struct cr_ddc_master *strMaster	=(struct cr_ddc_master *)lidb_handler;
	struct cr_ddc_path	*strPath	= NULL;

	strPath	= (struct cr_ddc_path *)malloc_z(struct cr_ddc_path);
	strPath->distance_metric	= 0;
//		strMaster->lastPath	= strPath;
	if(strPath)
	{
		strPath->connection		= CONNECTING;
		strPath->next			= strMaster->firstPath;
		strMaster->firstPath	= strPath;
		if(strMaster->lastPath == NULL)
		{
			strMaster->lastPath	= strPath;
		}
	}
	else
	{
		return NULL;
	}
	return strPath;
}
struct cr_ddc_linkShadow * linkShadow_is_exist(int lidb_handler,struct cr_lsdb_link_state *link)
{
	struct cr_ddc_master *lidb_master	=(struct cr_ddc_master *)lidb_handler;
	struct cr_ddc_linkShadow *p_linkShadow = lidb_master->first_linkShadow;
	while(p_linkShadow)
	{
		//printf("\n the link's address is %p\n",link);
		if((p_linkShadow->rt_id==link->key.rt_id && p_linkShadow->n_rt_id == link->key.n_rt_id )||(p_linkShadow->rt_id==link->key.n_rt_id && p_linkShadow->n_rt_id == link->key.rt_id ))
		{
			return p_linkShadow;
		}
		p_linkShadow = p_linkShadow->next;
	}

	return NULL;

}
int  cr_ddc_adjacentLinkShadowAndPath (int lidb_handler,int lsdb_handler,struct cr_ddc_path *p_path, 	struct cr_lsdb_link_state    *link,int source,int destination)
{

	struct cr_ddc_master *lidb_master	=(struct cr_ddc_master *)lidb_handler;
	struct cr_ddc_adjacent *strAdj;
	struct cr_ddc_linkShadow *linkShadow;
	int ra_allAccessLinkValue	;
	int rb_allAccessLinkValue	;

	strAdj	= (struct cr_ddc_adjacent *)malloc_z(struct cr_ddc_adjacent);
	if(!link)
	{
		return -1;
	}
	linkShadow	= linkShadow_is_exist(lidb_handler,link);
	if(!linkShadow)
	{
		linkShadow	= (struct cr_ddc_linkShadow *)malloc_z(struct cr_ddc_linkShadow);
		linkShadow->rt_id		= link->key.rt_id;
		linkShadow->if_id		= link->key.if_id;
		linkShadow->n_rt_id  = link->key.n_rt_id;
		linkShadow->n_if_id  = link->key.n_if_id;
		linkShadow->next	= lidb_master->first_linkShadow;
		lidb_master->first_linkShadow = linkShadow;
		if(!lidb_master->last_linkShadow)
		{
			lidb_master->last_linkShadow =linkShadow ;
		}
	}
	if(!strAdj)
	{
		return -1;
	}
	strAdj->path					= p_path;
	ra_allAccessLinkValue		= cr_ddc_getNodeALValue(lsdb_handler,source);
	rb_allAccessLinkValue		= cr_ddc_getNodeALValue(lsdb_handler,destination);
	//锟斤拷锟斤拷某锟斤拷
	strAdj->linkValue				= ra_allAccessLinkValue*rb_allAccessLinkValue;
	strAdj->next					= linkShadow->firstAdjacent;
	linkShadow->firstAdjacent	= strAdj;
	if(!linkShadow->lastAdjacent)
	{
		linkShadow->lastAdjacent		= strAdj;
	}
	return 0;
}

struct cr_ddc_linkShadow  * cr_ddc_linkShadowAdd(int lidb_handler)
{
	struct cr_ddc_master *lidb_master	=(struct cr_ddc_master *)lidb_handler;
	struct cr_ddc_linkShadow	*strLinkShadow	;

   strLinkShadow = (struct cr_ddc_linkShadow *)malloc_z(struct cr_ddc_linkShadow);

	if(!strLinkShadow)
	{
		return NULL;
	}
	strLinkShadow->firstAdjacent	= NULL;
	strLinkShadow->lastAdjacent	= NULL;

	strLinkShadow->next	= lidb_master->first_linkShadow;
	lidb_master->first_linkShadow	= strLinkShadow;
	if(!lidb_master->last_linkShadow)
	{
		lidb_master->last_linkShadow	= strLinkShadow;
	}
	return strLinkShadow;
}

int  cr_ddc_get_link_important_value (struct cr_lsdb_link_state *link,int lidb_handler,int lsdb_handle)
{

	int r_value=0;
	r_value=	ddc_link_important_value(link,lidb_handler,lsdb_handle);
	if(r_value!=0)
	{
		return r_value;
	}
	else
	{
		return -1;
	}

}
static int  ddc_link_important_value (struct cr_lsdb_link_state *link,int lidb_handler,int lsdb_handle)
{
	printf("\n(cr_ddc_link_important_value)%d:%d--->%d:%d  \n ", link->key.rt_id,link->key.if_id,link->key.n_rt_id,link->key.n_if_id);

	int   intValue=0;
	struct link_state_key key;
	struct cr_lsdb_link_state link_new ;
	struct cr_ddc_linkShadow *p_linkShadow	=linkShadow_is_exist(lidb_handler,link);
	struct cr_ddc_adjacent	*strAdj = NULL;
		if(!p_linkShadow)
		{
			return -1;
		}
		else
		{
			strAdj	= p_linkShadow->firstAdjacent;
		}
		if(strAdj->path ==NULL)
		{
			printf("\nthere is no path\n");
			return -1;
		}
		while(strAdj)
		{
			intValue+=strAdj->path->spathValue;
			//intValue++;
			//printf("%d--->%d   ", strAdj->path->raID,strAdj->path->rbID);
			strAdj	= strAdj->next;
		}
		return intValue;
}


int cr_ddc_getPathTotalValue(int lidb_handler)
{
	struct cr_ddc_master *lidb_master	=(struct cr_ddc_master *)lidb_handler;
	int flTotalValue=0;
	int netPathAllValue;
	struct cr_ddc_path *strPath	= NULL;
	strPath			=lidb_master->firstPath;
	while(strPath)
	{
		if(strPath->connection==UNCONNECTING)
		{
			flTotalValue=flTotalValue+strPath->spathValue;
		}
		strPath	= strPath->next;
	}
	netPathAllValue= cr_ddc_getNetPathAllValue(lidb_handler);
	flTotalValue	= 100*(flTotalValue/netPathAllValue);
	//printf("%f",flTotalValue);
	return flTotalValue;
}
int 	 cr_ddc_getNetPathAllValue(int lidb_handler)
{
	int netPathAllValue =0;
	struct cr_ddc_master *lidb_master	=(struct cr_ddc_master *)lidb_handler;

	struct cr_ddc_path *strPath	= NULL;

		strPath			=lidb_master->firstPath;
		while(NULL!=strPath)
		{
			netPathAllValue=netPathAllValue+strPath->spathValue;
			strPath	= strPath->next;
		}

		if(netPathAllValue<=0)
		{
			netPathAllValue = 1;
		}
		return netPathAllValue;
}

int	cr_ddc_pathStateDown(struct cr_ddc_linkShadow *p_linkShadow)
{
	struct cr_ddc_adjacent	 *strAdj;
	if(NULL==p_linkShadow)
	{
		return 0;
	}
	else
	{
		strAdj			= p_linkShadow->firstAdjacent;
	}
	if(NULL==strAdj)
	{
		return 1;
	}
	while(strAdj)
	{
		if(strAdj->path!=NULL)
		{
		strAdj->path->connection	= UNCONNECTING;
		}
		strAdj						= strAdj->next;

	}
	return 2;
}

int	cr_ddc_pathStateUp(struct cr_ddc_linkShadow *p_linkShadow)
{
	struct cr_ddc_adjacent	 *strAdj;
	if(NULL==p_linkShadow)
	{
		return 0;
	}
	else
	{
		strAdj			= p_linkShadow->firstAdjacent;
	}
	if(NULL==strAdj)
	{
		return 1;
	}
	while(strAdj)
	{
		strAdj->path->connection	= CONNECTING;
		strAdj						= strAdj->next;
	}
	return 2;//锟缴癸拷
}

int cr_ddc_getPathValue(int p_raID,int p_rbID,int lidb_handler)
{
	struct cr_ddc_master *lidb_master	=(struct cr_ddc_master *)lidb_handler;
	struct cr_ddc_path	*path	= lidb_master->firstPath;
	while(path)
	{
		if(path->raID==p_raID&&path->rbID==p_rbID)
		{

			return path->spathValue;
		}
		path=path->next;

	}
	return 0;
}

void printMatch(struct cr_floyd_match *strMatchHead,int len)
{
	struct cr_floyd_match *p;
	int length	= len;
	int i;
	for(i=0;i<length;i++)
	{
		p= (struct cr_floyd_match *)((char *)strMatchHead + i*sizeof(struct cr_floyd_match));
		printf("%2d   ",p->num);
		printf("(%2d) ",p->routerID);
		printf("\n");
	}
	printf("t %d\n",i);
}

int cr_ddc_find_distance(u_int32_t head_rt_id,u_int32_t tail_rt_id, int lidb_handler)
{
	struct cr_ddc_master *lidb_master	=(struct cr_ddc_master *)lidb_handler;
	struct cr_ddc_path	*path	= lidb_master->firstPath;
	while(path)
		{
			if((path->raID==head_rt_id&&path->rbID==tail_rt_id)||(path->raID==tail_rt_id&&path->rbID==head_rt_id))
			{
				return path->distance_metric;
			}
			path=path->next;

		}
		return -1;
}

int cr_ddc_find_next_hop(u_int32_t head_rt_id,u_int32_t tail_rt_id, int lidb_handler)
{
	struct cr_ddc_master *lidb_master	=(struct cr_ddc_master *)lidb_handler;
	struct cr_ddc_path	*path	= lidb_master->firstPath;
	while(path)
		{
			if((path->raID==head_rt_id&&path->rbID==tail_rt_id)||(path->raID==tail_rt_id&&path->rbID==head_rt_id))
			{
				return path->next_hop_router_id;
			}
			path=path->next;

		}
		return -1;
}

float get_destory_degree(struct link_state_key *key, int lsdb_handler, int lidb_handler)
{
	printf("\n======into the get destroy degree=======\n");
	//struct cr_ddc_master *lidb_master	=(struct cr_ddc_master *)lidb_handler;
	struct cr_lsdb_link_state *link = (struct cr_lsdb_link_state *)malloc_z(struct cr_lsdb_link_state);


	int link_value;
	int net_value;
	float value;
	cr_lsdb_link_state_find(key, link, lsdb_handler);

	printf("\n%d:%d--->%d:%d  \n ", link->key.rt_id,link->key.if_id,link->key.n_rt_id,link->key.n_if_id);


	link_value = cr_ddc_get_link_important_value (link,lidb_handler,lsdb_handler);
	net_value = cr_ddc_getNetPathAllValue(lidb_handler);
	value = link_value/net_value;
   free(link);
	return value;
}

int cr_ddc_find_protected_node_in_frr(struct cr_lsdb_link_state *link,
		struct rt_node_list **node_head, int lidb_handle)
{
	struct cr_ddc_adjacent	 *strAdj = ((struct  cr_ddc_linkShadow *)(link->shadow))->firstAdjacent;
	struct rt_node_list *node;
	node = (struct rt_node_list *)malloc(sizeof(struct rt_node_list));
	struct cr_ddc_path *path;
	*node_head = NULL;

	while(strAdj)
	{
		struct rt_node_list* tmp = (struct rt_node_list *)malloc(sizeof(struct rt_node_list));
		path = strAdj->path;
		if(path->raID == link->key.rt_id)
		{
			tmp->rt_id = path->rbID;
		}
		else
			tmp->rt_id = path->raID;
		tmp->next = *node_head;
		*node_head = tmp;
		strAdj	= strAdj->next;
	}

	return 0;
}
